package ilvonen.ihstatistics.repository;

import ilvonen.ihstatistics.models.ConstantData;

import java.util.ArrayList;
import java.util.List;

import android.content.ContentValues;
import android.database.Cursor;

public class DBSeasonTypes {
	//define table name
	private static final String TABLE_NAME = "season_types";
//define tables column names
	private static final String KEY_ID = "_id";
	private static final String KEY_NAME = "name";
//define create statement for all your tables. Create new file (class) for each table.
	private static final String CREATE_STATEMENT = "create table if not exists " + TABLE_NAME + " (" + KEY_ID + " integer primary key autoincrement, " + KEY_NAME + " text not null);";

/*
 * CLASS STATUS: READY!
 */
public DBSeasonTypes(){}
/*
 * 
 */
public String create(){
	return CREATE_STATEMENT;
}
/*
 * insert new values. this should be not used in this android program. seasontypes should be added throug web interface
 */
public long insert(String name, DBAdapter db){
	
	ContentValues initialValues = new ContentValues();
	initialValues.put(KEY_NAME, name);
	
	return db.insertRecord(TABLE_NAME, initialValues);
	
}
/*
 * delete records. seasontypes should not be deleted.
 */
public boolean delete(long rowId, DBAdapter db){
	return db.deleteRecord(TABLE_NAME, KEY_ID, rowId);
}
/*
 * Get list of all seasontypes.
 */
public List<ConstantData> getAllSeasonTypes(DBAdapter db){
	Cursor c;
	List<ConstantData> s = new ArrayList<ConstantData>();
	c = db.getAllRecords(TABLE_NAME, new String[]{KEY_ID,KEY_NAME});
	while(c.moveToNext()){
		ConstantData data = new ConstantData();
		data.set_id(c.getInt(0));
		data.set_name(c.getString(1));

		s.add(data);
	}
	return s;
}
/*
 * Get one seasontype identified by id
 */
public ConstantData getSeasonTypeById(DBAdapter db, long ROW_ID){
	ConstantData s = null;
	Cursor c;
	c = db.getRecord(TABLE_NAME, new String[]{KEY_ID,KEY_NAME}, KEY_ID, ROW_ID);
	if(c != null){
		s = new ConstantData();
		c.moveToFirst();
		s.set_id(c.getInt(0));
		s.set_name(c.getString(1));
	}
	return s;
}
}
